//
//  htvme.m
//  WZYApp
//
//  Created by zhangwq on 16/1/27.
//  Copyright © 2016年 HT. All rights reserved.
//

#import "htvme.h"
#import "HTSysParam.h"
#import "HTFrameNet.h"
#import "UIImageView+WebCache.h"

@interface htvme (){
    CGFloat width;
    CGFloat height;
    UIColor *backColor;
    UIView *uv;
    NSDictionary *dictMe;
    UIImageView *avatar;
    
}


@property (nonatomic, strong) NSOperationQueue *queue;

@end

@implementation htvme

- (NSOperationQueue *)queue {
    if (!_queue) _queue = [[NSOperationQueue alloc] init];
    return _queue;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    CGRect rect = [[UIScreen mainScreen] bounds];
    CGSize size = rect.size;
    width = size.width;
    height = size.height;
    
    dictMe=[[NSDictionary alloc]init];
    backColor=[UIColor colorWithRed:150.0/255 green:150.0/255 blue:150.0/255 alpha:1.0f];
    
    self.tableView.separatorStyle=NO;
    
    uv=[[UIView alloc]init];
    
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    

    
}




-(void)loginAction:(id)sender{
    
    NSString *storyboard=@"MYLogin";
    NSString *Identifier=@"MYLogin";
    UIStoryboard *valueView = [UIStoryboard storyboardWithName:storyboard bundle:nil];
    UIViewController *uv=[valueView instantiateViewControllerWithIdentifier:Identifier];
    UINavigationController *baNavigation = [[UINavigationController alloc] initWithRootViewController:uv];
    [self presentModalViewController:baNavigation animated:YES];
    
    //返回
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if(section==0){
        return 1;
    }
    else{
        return 3;
    }

}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if([indexPath section]==0){
        return 160.0;
    }
    else{
        return 55.0;
    }
}




- ( UITableViewCell *)tableView:( UITableView *)tableView cellForRowAtIndexPath:( NSIndexPath *)indexPath{
    
    NSString *cellId = @"cellname" ;
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier :cellId];
    if (cell == nil ) {
        cell = [[ UITableViewCell alloc ] initWithStyle : UITableViewCellStyleDefault reuseIdentifier :cellId] ;
    }
    
    uv=[[UIView alloc]initWithFrame:CGRectMake(0, 0, width, 70)];
    
    
    if([indexPath section]==0){
        uv=[[UIView alloc]initWithFrame:CGRectMake(0, 0, width, 160)];
        UIImageView *photo=[[UIImageView alloc]initWithFrame:CGRectMake(16, 0, width, 160)];
        photo.image=[UIImage imageNamed:@"backme"];
        [photo setClipsToBounds:YES];
        [photo setContentMode:UIViewContentModeScaleAspectFill];
        photo.layer.masksToBounds=YES;
        [uv addSubview:photo];
        
        
        avatar=[[UIImageView alloc]initWithFrame:CGRectMake(width/2-50, 40, 80, 80)];
        avatar.image=[UIImage imageNamed:@"avatar.jpg"];
        avatar.layer.cornerRadius=40;
        [avatar setClipsToBounds:YES];
        [avatar setContentMode:UIViewContentModeScaleToFill];
        avatar.layer.masksToBounds=YES;
        [photo addSubview:avatar];
        

        
    }
    
    
    if([indexPath section]==1){
        if([indexPath row]==0){
            
            uv=[[UIView alloc]initWithFrame:CGRectMake(0, 0, width, 55)];
            UIImageView *photo=[[UIImageView alloc]initWithFrame:CGRectMake(30, 17.5, 20, 20)];
            photo.image=[UIImage imageNamed:@"set"];
            [photo setClipsToBounds:YES];
            [photo setContentMode:UIViewContentModeScaleAspectFill];
            photo.layer.masksToBounds=YES;
            [uv addSubview:photo];
            
            
            UIImageView *photo2=[[UIImageView alloc]initWithFrame:CGRectMake(width-25, 17.5, 20, 20)];
            photo2.image=[UIImage imageNamed:@"xing"];
            [photo2 setClipsToBounds:YES];
            [photo2 setContentMode:UIViewContentModeScaleAspectFill];
            photo2.layer.masksToBounds=YES;
            [uv addSubview:photo2];
            
            
            UILabel *lb=[[UILabel alloc]initWithFrame:CGRectMake(80, 15, 100, 25)];
            lb.text=@"我的设置";
            lb.textColor=backColor;
            lb.font=[UIFont fontWithName:@"Arial" size:14.0];
            [uv addSubview:lb];
            
            UIView *line=[[UIView alloc]initWithFrame:CGRectMake(20, 54, width, 0.6)];
            line.backgroundColor=[UIColor colorWithRed:180.0/255.0 green:180.0/255.0 blue:180.0/255.0 alpha:1.0];
            [uv addSubview:line];
            
            
        }
        
        if([indexPath row]==1){
            
            uv=[[UIView alloc]initWithFrame:CGRectMake(0, 0, width, 55)];
            UIImageView *photo=[[UIImageView alloc]initWithFrame:CGRectMake(30, 17.5, 20, 20)];
            photo.image=[UIImage imageNamed:@"gai"];
            [photo setClipsToBounds:YES];
            [photo setContentMode:UIViewContentModeScaleAspectFill];
            photo.layer.masksToBounds=YES;
            [uv addSubview:photo];
            
            UIImageView *photo2=[[UIImageView alloc]initWithFrame:CGRectMake(width-25, 17.5, 20, 20)];
            photo2.image=[UIImage imageNamed:@"xing"];
            [photo2 setClipsToBounds:YES];
            [photo2 setContentMode:UIViewContentModeScaleAspectFill];
            photo2.layer.masksToBounds=YES;
            [uv addSubview:photo2];
            
            UILabel *lb=[[UILabel alloc]initWithFrame:CGRectMake(80, 15, 100, 25)];
            lb.text=@"修改密码";
            lb.textColor=backColor;
            lb.font=[UIFont fontWithName:@"Arial" size:14.0];
            [uv addSubview:lb];
            
            UIView *line=[[UIView alloc]initWithFrame:CGRectMake(20, 54, width, 0.6)];
            line.backgroundColor=[UIColor colorWithRed:180.0/255.0 green:180.0/255.0 blue:180.0/255.0 alpha:1.0];
            [uv addSubview:line];
            
            
        }
        
        if([indexPath row]==2){
            
            uv=[[UIView alloc]initWithFrame:CGRectMake(0, 0, width, 55)];
            UIImageView *photo=[[UIImageView alloc]initWithFrame:CGRectMake(30, 17.5, 20, 20)];
            photo.image=[UIImage imageNamed:@"tui"];
            [photo setClipsToBounds:YES];
            [photo setContentMode:UIViewContentModeScaleAspectFill];
            photo.layer.masksToBounds=YES;
            [uv addSubview:photo];
            
            UIImageView *photo2=[[UIImageView alloc]initWithFrame:CGRectMake(width-25, 17.5, 20, 20)];
            photo2.image=[UIImage imageNamed:@"xing"];
            [photo2 setClipsToBounds:YES];
            [photo2 setContentMode:UIViewContentModeScaleAspectFill];
            photo2.layer.masksToBounds=YES;
            [uv addSubview:photo2];
            
            UILabel *lb=[[UILabel alloc]initWithFrame:CGRectMake(80, 15, 100, 25)];
            lb.text=@"退出登录";
            lb.textColor=backColor;
            lb.font=[UIFont fontWithName:@"Arial" size:14.0];
            [uv addSubview:lb];
            
            UIView *line=[[UIView alloc]initWithFrame:CGRectMake(20, 54, width, 0.6)];
            line.backgroundColor=[UIColor colorWithRed:180.0/255.0 green:180.0/255.0 blue:180.0/255.0 alpha:1.0];
            [uv addSubview:line];
            
            
            UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(exitAction:)];
            [uv addGestureRecognizer:tapGesture];
            
            
        }
    }
    
    
    
    
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryView=uv;
    
    return cell;
}

//退出
-(void)exitAction:(UITapGestureRecognizer*)Sender{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    //从用户配置中移除保存对象
    [defaults removeObjectForKey:@"password"];
    //写入文件
    [defaults synchronize];
    
    
    
    
    NSString *storyName=@"";
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        storyName=@"HTMain_New";
    }
    else{
        storyName=@"HTMain_IPAD";
    }
    
    
    UIStoryboard *mainStory = [UIStoryboard storyboardWithName:storyName bundle:nil];
    UIViewController *login = [mainStory instantiateViewControllerWithIdentifier:@"htvlogin_new"];
    
    
    //跳转到登录页面
    [self presentViewController:login animated:YES completion:nil];
}


//我的订单
-(void)orderAction:(UITapGestureRecognizer*)Sender{
    NSString *storyboard=@"OrderForm";
    NSString *Identifier=@"OrderForm";
    UIStoryboard *valueView = [UIStoryboard storyboardWithName:storyboard bundle:nil];
    UIViewController *uv=[valueView instantiateViewControllerWithIdentifier:Identifier];
    UINavigationController *baNavigation = [[UINavigationController alloc] initWithRootViewController:uv];
    [self presentModalViewController:baNavigation animated:YES];
    
    //返回
    
}

//商品收藏
-(void)collectionAction:(UITapGestureRecognizer*)Sender{
    NSString *storyboard=@"CollectionForm";
    NSString *Identifier=@"CollectionForm";
    UIStoryboard *valueView = [UIStoryboard storyboardWithName:storyboard bundle:nil];
    UIViewController *uv=[valueView instantiateViewControllerWithIdentifier:Identifier];
    UINavigationController *baNavigation = [[UINavigationController alloc] initWithRootViewController:uv];
    [self presentModalViewController:baNavigation animated:YES];
    
    //返回
    
}


- (IBAction)searchAction:(UIButton *)sender {
    NSString *storyboard=@"SampleQuery";
    NSString *Identifier=@"SampleQuery";
    UIStoryboard *valueView = [UIStoryboard storyboardWithName:storyboard bundle:nil];
    UIViewController *uv=[valueView instantiateViewControllerWithIdentifier:Identifier];
    UINavigationController *baNavigation = [[UINavigationController alloc] initWithRootViewController:uv];
    [self presentModalViewController:baNavigation animated:YES];
    
    //返回

}
@end
